axios.defaults.headers.Authorization = localStorage.getItem('token') || ''
const VM = new Vue({
  el: "#app",
  data: {
    title_data: {},
    activeName: "first",
    student_name: '',
    selected_title: '',
    data: {},
    student_answer: {}
  },
  methods: {
    handleClick(tab, event) {
      // console.log(tab, event);
    },
    aa() {
      axios.post('http://127.0.0.1:8000/api/get_homework_titile_student').then((res) => {
        console.log(res);
        this.title_data = res.data

      })
    },
    get_title(e) {
      e.target.id = 'tit'
      this.aa();
      this.$refs.fm.contentWindow.fmvm.bb()
      e.target.id = ''
    },
    get_student_homework(e) {
      this.selected_title = e.target.innerHTML
      axios.post('http://127.0.0.1:8000/my/inspect').then((res) => {
        this.student_name = res.data
        // console.log(this.student_name);

      })
    },
    get_student_answer(e) {
      const student_name = e.target.id
      let data
      data = JSON.stringify({
        name: student_name,
        title: this.selected_title
      })
      // console.log(student_name);
      // console.log(this.selected_title);
      // const data = JSON.stringify([ student_name,VM.selected_title ])
      axios.post('http://127.0.0.1:8000/my/get_student_answer', `${data}`).then((res) => {
        // console.log(res.data[0]);
        if (!res.data[0]) {
          this.data = null
          return alert('这个逼没交作业')
        }
        // console.log(res);
        this.student_answer = JSON.parse(res.data[0].answer)

        console.log(this.student_answer);
        // console.log(this.student_answer);

      })
      const data_title = this.selected_title
      axios.post('http://127.0.0.1:8000/api/get_homework_student', data_title).then((res) => {
        if (res.data) {
          // console.log(res.data.homework);
          this.data = JSON.parse(res.data.homework)
          console.log(this.data);

        }
        //   window.parent.document.getElementById('iframeBox').style.height = window.document.documentElement.offsetHeight + 200 + 'px'
        //   console.log(window.parent.document.getElementById('iframeBox'), 'asdfasdf',  window.document.documentElement.offsetHeight)
      })

    }
  },
  created() {
    this.aa()
  }
})